home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '93 / Papers '93 / Macintosh as Internet Server ƒ / inetd / Libraries / MacTCPLib / DNR.c next >
Encoding:
C/C++ Source or Header  |  1993-03-17  |  1.7 KB  |  107 lines  |  [TEXT/MPS ]

  1.  
  2. #include "DNR.h"
  3.  
  4. #include <Desk.h>
  5. #include <StdLib.h>
  6.  
  7. pascal void __DNRDone(struct hostInfo* info, char* usrPtr);
  8.  
  9. OSErr
  10. dnrNameToAddr(char* name, ip_addr* addr, ResultProcPtr proc, char* usrPtr)
  11. {
  12.     OSErr            theErr;
  13.     ResultProcPtr    done;
  14.     struct hostInfo    hinfo;
  15.     
  16.     if (proc)
  17.         done = proc;
  18.     else
  19.         done = &__DNRDone;
  20.  
  21.     theErr = OpenResolver(nil);
  22.     
  23.     if (theErr == noErr) 
  24.         theErr = StrToAddr(name, &hinfo, done, usrPtr);
  25.         
  26.     if ((theErr == noErr) || (theErr == cacheFault)) {
  27.         while (hinfo.rtnCode == cacheFault)
  28.             SystemTask();
  29.             
  30.         CloseResolver();
  31.         
  32.         if (hinfo.rtnCode == noErr)
  33.             *addr = hinfo.addr[0];
  34.             
  35.         theErr = (OSErr) hinfo.rtnCode;
  36.     }
  37.  
  38.     return theErr;
  39. }
  40.  
  41. OSErr
  42. dnrAddrToName(ip_addr addr, char* name, ResultProcPtr proc, char* usrPtr)
  43. {
  44.     OSErr            theErr;
  45.     ResultProcPtr    done;
  46.     struct hostInfo    hinfo;
  47.     int                i;
  48.     
  49.     if (proc)
  50.         done = proc;
  51.     else
  52.         done = &__DNRDone;
  53.     
  54.     theErr = OpenResolver(nil);
  55.     
  56.     if (theErr == noErr) 
  57.         theErr = AddrToName(addr, &hinfo, done, usrPtr);
  58.     
  59.     if ((theErr == noErr) || (theErr == cacheFault)) {
  60.         while (hinfo.rtnCode == cacheFault)
  61.             SystemTask();
  62.         
  63.         CloseResolver();
  64.         
  65.         if (hinfo.rtnCode == noErr) {
  66.             i = strlen(hinfo.cname) - 1;
  67.             if (hinfo.cname[i] == '.')
  68.                 hinfo.cname[i] = 0;
  69.  
  70.             strcpy(name, hinfo.cname);
  71.         }
  72.         
  73.         theErr = (OSErr) hinfo.rtnCode;
  74.     }
  75.     
  76.     return theErr;
  77. }
  78.  
  79. OSErr
  80. dnrDotsToAddr(char* dots, ip_addr* addr)
  81. {
  82.     OSErr            theErr;
  83.     struct hostInfo    hinfo;
  84.     
  85.     theErr = OpenResolver(nil);
  86.     
  87.     if (theErr == noErr) 
  88.         theErr = StrToAddr(dots, &hinfo, &__DNRDone, nil);
  89.         
  90.     if (theErr == noErr)
  91.         *addr = hinfo.addr[0];
  92.  
  93.     return theErr;
  94. }
  95.  
  96. OSErr
  97. dnrAddrToDots(ip_addr addr, char* dots)
  98. {
  99.     return AddrToStr(addr, dots);
  100. }
  101.  
  102. pascal void
  103. __DNRDone(struct hostInfo* , char* )
  104. {
  105.     // do nothing by default
  106. }
  107.